#!/usr/bin/python
#coding:utf8
'''
State
'''
from abc import ABC, abstractmethod
# 咖啡机的状态基类
class CoffeeMachineState(ABC):
    @abstractmethod
    def insertCoin():
        pass
    @abstractmethod
    def selectCoffee():
        pass
    @abstractmethod
    def dispenseCoffee():
        pass
# 实现咖啡机的三个状态类
class IdleState(CoffeeMachineState):
    def __init__(self, machine):
        self.machine = machine
    def insertCoin(self):
        print("投入硬币成功，请选择咖啡。")
        self.machine.setState(self.machine.selecting_state)
    def selectCoffee(self):
        print("请先投币。")
    def dispenseCoffee(self):
        print("请先投币并选择咖啡。")
    def __repr__(self):
        return "IdleState"

class SelectingState(CoffeeMachineState):
    def __init__(self, machine):
        self.machine = machine
    def insertCoin(self):
        print("硬币已投入，不要重复投币，请选择咖啡。")
    def selectCoffee(self):
        print("咖啡正在制作中.....")
        self.machine.setState(self.machine.dispensing_state)
    def dispenseCoffee(self):
        print("请先选择咖啡。")
    def __repr__(self):
        return "SelectingState"

class DispensingState(CoffeeMachineState):
    def __init__(self, machine):
        self.machine = machine
    def insertCoin(self):
        print("咖啡已制作完成，不要投币。")
    def selectCoffee(self):
        print("咖啡已制作完成，不要选择咖啡。")
    def dispenseCoffee(self):
        print("请取走您的咖啡。")
        self.machine.setState(self.machine.idle_state)
    def __repr__(self):
        return "DispensingState"

# 咖啡机类
class CoffeeMachine:
    def __init__(self):
        self.idle_state = IdleState(self)
        self.selecting_state = SelectingState(self)
        self.dispensing_state = DispensingState(self)
        self.current_state = self.idle_state
    def setState(self, state):
        self.current_state = state
    def insertCoin(self):
        self.current_state.insertCoin()
    def selectCoffee(self):
        self.current_state.selectCoffee()
    def dispenseCoffee(self):
        self.current_state.dispenseCoffee()
    
if __name__ == '__main__':
    machine = CoffeeMachine()
    operations = []
    operations.append(machine.insertCoin)
    operations.append(machine.selectCoffee)
    operations.append(machine.dispenseCoffee)
    operations.append(
    machine.dispenseCoffee)
    for operation in operations:
        print(f"当前咖啡机状态： {machine.current_state}")
        operation()